<?php
/**
 * Created by PhpStorm.
 * User: LOPO
 * Date: 2020/4/15
 * Time: 14:15
 */
namespace App\HttpController\Api;

use EasySwoole\Http\AbstractInterface\Controller;

class Base extends Controller
{

    /**
     * 放一些请求的参数数据
     * @var array
     */
    public $params = [];
    public function index()
    {
        // TODO: Implement index() method.
    }

    /**权限相关
     * @param \EasySwoole\Http\AbstractInterface\string|null $action
     * @return bool|null
     */
    public function onRequest($action): ? bool
    {
        $this->getParams();
        return true;
    }
    /**
     * 获取 params
     * @auth   singwa
     * @return [type] [description]
     */
    public function getParams() {
        $params = $this->request()->getRequestParam();
        $params['page'] = !empty($params['page']) ? intval($params['page']) : 1;
        $params['size'] = !empty($params['size']) ? intval($params['size']) : 5;

        $params['from'] = ($params['page'] - 1) * $params['size'];

        $this->params = $params;
    }

//    public function onException(\Throwable $throwable): void
//    {
//        $this->writeJson(400,'请求不合法');
//    }

}